package com.xfatm.simplebrowser.util;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wenjie on 2018/3/12.
 */

public class BeanManageUtils {
    private static Map<String,Object> beanMap=new HashMap<>();

    /**当前显示activity*/
    public static final String SHOW_ACTIVITY="showActivity";

    public static void saveBean(String name,Object object){
        beanMap.put(name,object);
    }

    public static void saveBean(int id,Object object){
        saveBean(String.valueOf(id),object);
    }

    public static <T> T getBean(String name,Class<? extends T> clazz){
        Object obj=beanMap.get(name);
        if(obj==null)return null;
        try{
            return (T)obj;
        }catch (Exception e){
            throw new RuntimeException("类型转换失败");
        }
    }
    public static <T> T getBean(int id,Class<? extends T> clazz){
        return getBean(String.valueOf(id),clazz);
    }

    public static String getString(String name){
        return getBean(name,String.class);
    }

    public static int getInt(String name){
        Integer i=getBean(name,Integer.class);
        if(i==null){
            return 0;
        }
        return i;
    }
}
